package cn.pigeon.health.service.impl;

import cn.pigeon.health.dao.MemberDao;
import cn.pigeon.health.pojo.Member;
import cn.pigeon.health.service.MemberService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 会员服务层实现类
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    /**
     * 根据条件查询会员
     * @param map
     * @return
     */
    public Member findByCondition(Map map) {
        return memberDao.findByCondition(map);
    }

    /**
     * 添加会员
     * @param member
     */
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 根据月份集合查询会员数量
     * @param lstMonths
     * @return
     */
    public List<Integer> findMemberCountByMonth(List<String> lstMonths) {
        List<Integer> lstCounts = new ArrayList<>();

        for (String month : lstMonths) {
            String searchDate = month+ ".31";
            Integer count = memberDao.findCountByBeforeDate(searchDate);
            lstCounts.add(count);
        }

        return lstCounts;
    }
}
